/*
 * USART_3200.c
 *
 * Created: 9/13/2012 8:54:48 PM
 *  Author: zimmermane
 */ 

#include "USART_3200.h"
#include <avr/io.h>
#define F_CPU 16E6         // CPU clock speed for delay.h
#include <util/delay.h>
/*
 * set_baud
 * Purpose: Used to set the baud rate on the USART
 * Parameters: uint16_t baud the passed in baud rate value
 * Returns: None
 */
void set_baud(uint16_t baud){
	 UBRRH = (uint8_t)(baud>>8);
	 UBRRL = (uint8_t)(baud & 0x00FF);
}

/*
 * usart_send_data
 * Purpose: Used to send the data to the LCD
 * Parameters: uint8_t data the data to be sent
 * Returns: None
 */
void usart_send_data(uint8_t data){
	//delay for sending
	_delay_ms(20);
	//wait for the transmit flag to be ready
	while(!(UCSRA & (1<<UDRE)));
	//load the data
	UDR = data;
}

/*
 * INIT_USART
 * Purpose: Initialize the USART for the LCD and the RFID
 * Parameters: None
 * Returns: None
 */
void INIT_USART(void){
	//turn on USART Receive and Transmit Interrupt
	//Turn on Receive enable and Transmit enable
	UCSRB = (1<<RXCIE) | (1<<TXCIE) | (1<<RXEN) | (1<<TXEN);
}